#!/usr/bin/env python3

import os
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AyatanaAppIndicator3', '0.1')
from gi.repository import Gtk, AyatanaAppIndicator3

APPINDICATOR_ID = "Zram Tools"

def script1(widget):
    os.popen("/usr/share/zram-tools-gui/scripts/pwd-start")

def script2(widget):
    os.popen("/usr/share/zram-tools-gui/scripts/pwd-stop")

def script3(widget):
    os.popen("/usr/share/zram-tools-gui/scripts/pwd-restart")

def script4(widget):
    os.popen("/usr/share/zram-tools-gui/scripts/pwd-status")

def script5(widget):
    os.popen("/usr/share/zram-tools-gui/scripts/pwd-editor")

def script6(widget):
    os.popen("/usr/share/zram-tools-gui/about/ZramTools")

def script7(widget):
    os.popen("pkill -f 'Zram Tools'")

def build_menu():
    menu = Gtk.Menu()
    items = [
        ("🟢️ Start", script1, "Start ZramTools"),
        ("🔴️ Stop", script2, "Stop ZramTools"),
        ("♻️ Restart", script3, "Restart ZramTools"),
        ("⚡️ Status", script4, "Status ZramTools"),
        ("📝️ Edit", script5, "Edit ZramTools"),
        ("⭐️ About", script6, "About ZramTools"),
        ("❌️ Quit", script7, "Quit ZramTools"),

    ]

    for label, callback, tip in items:
        item = Gtk.MenuItem(label=label)
        item.connect('activate', callback)
        item.set_tooltip_text(tip)
        menu.append(item)

    menu.show_all()
    return menu

indicator = AyatanaAppIndicator3.Indicator.new(
    APPINDICATOR_ID,
    "/usr/share/icons/hicolor/48x48/apps/zram-tools.png",
    AyatanaAppIndicator3.IndicatorCategory.APPLICATION_STATUS
)

indicator.set_status(AyatanaAppIndicator3.IndicatorStatus.ACTIVE)
indicator.set_menu(build_menu())

Gtk.main()

